package textapp.dao.model;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@NamedQueries({
	@NamedQuery(name="GroupUser.getByGroup", query="select gu from GroupUser gu where gu.group = :group"),
	@NamedQuery(name="GroupUser.getByUser", query="select gu from GroupUser gu where gu.user = :user")
	
})

@Entity
@Table(name="group_user")
public class GroupUser {
	
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "guid", nullable = false)
	private int id;
	
	@ManyToOne
	@JoinColumn(name="gid", nullable=false)
	private Group group;
	
	@ManyToOne
	@JoinColumn(name="uid", nullable=false)
	private User user;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Group getGroup() {
		return group;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof GroupUser)) {
			return false;
		}
		GroupUser other = (GroupUser) obj;
		if (other.getId() == 0) {
			return false;
		}
		return this.group.equals(other.getGroup()) && this.user.equals(other.getUser());
	}
	
}
